# 熵阈值敏感性数据
lambda_M = [0.5, 0.6, 0.7, 0.8]
comm_cost = [7.2, 5.4, 4.1, 6.3]  # MB/round
energy = [8.5, 6.8, 5.9, 7.6]     # J/round
accuracy = [75.3, 78.2, 80.1, 76.8] # %

# 创建双Y轴图
fig, ax1 = plt.subplots(figsize=(10, 6))
ax1.plot(lambda_M, comm_cost, 'bo-', label='Communication Cost')
ax1.plot(lambda_M, energy, 'rs--', label='Energy Consumption')
ax1.set_xlabel(r'Entropy Threshold $\lambda_M$', fontsize=14)
ax1.set_ylabel('System Cost', fontsize=14)
ax1.grid(alpha=0.3)

# 第二个Y轴（精度）
ax2 = ax1.twinx()
ax2.plot(lambda_M, accuracy, 'g^-', label='Accuracy')
ax2.set_ylabel('Accuracy (%)', fontsize=14)

# 标注最优区间
# ax1.axvspan(0.65, 0.75, alpha=0.2, color='yellow')
# ax1.text(0.7, 6, 'Optimal Range\n(λ_M=0.6-0.7)', 
#          ha='center', fontsize=10, bbox=dict(facecolor='white', alpha=0.8))

# plt.title(r'Sensitivity to Entropy Threshold $\lambda_M$', fontsize=14)
fig.legend(loc='upper left', bbox_to_anchor=(0.15, 0.85),prop={'size': 14, 'family': 'SimHei'})
plt.savefig('threshold_sensitivity_en.png', bbox_inches='tight')
